#include "MouseEvent.h"
#include <windowsx.h>

MouseEvent::MouseEvent(UIControl* p_pSender, UINT p_uMsg, WPARAM p_wParam, LPARAM p_lParam) : UIEvent(p_pSender), m_uButton(0), m_isDBClick(false)
{
	switch (p_uMsg)
	{
	case WM_LBUTTONDBLCLK:
		m_uButton |= MK_LBUTTON;
		m_isDBClick = true;
		break;
	case WM_RBUTTONDBLCLK:
		m_uButton |= MK_RBUTTON;
		m_isDBClick = true;
		break;
	case WM_MBUTTONDOWN:
		m_uButton |= MK_MBUTTON;
		break;
	case WM_LBUTTONDOWN:
		m_uButton |= MK_LBUTTON;
		break;
	case WM_RBUTTONDOWN:
		m_uButton |= MK_RBUTTON;
		break;
	case WM_MBUTTONUP:
	case WM_LBUTTONUP:
	case WM_RBUTTONUP:
	case WM_MOUSEMOVE:
		break;	
	default:
		return;
	}
	m_uButton |= p_wParam;
	m_iX = GET_X_LPARAM(p_lParam);
	m_iY = GET_Y_LPARAM(p_lParam);
}
MouseEvent::~MouseEvent()
{
}
int MouseEvent::getX()
{
	return m_iX;
}
int MouseEvent::getY()
{
	return m_iY;
}
bool MouseEvent::isButtonDown(UINT p_uButton)
{
	return (m_uButton & p_uButton) != 0;
}

bool MouseEvent::isCTRLButtonDown()
{
	return (m_uButton & MK_CONTROL) != 0;
}

bool MouseEvent::isShiftButtonDown()
{
	return (m_uButton & MK_SHIFT) != 0;
}

bool MouseEvent::isLButtonDown()
{
	return (m_uButton & MK_LBUTTON) != 0;
}

bool MouseEvent::isRButtonDown()
{
	return(m_uButton & MK_RBUTTON) != 0;
}

bool MouseEvent::isMButtonDown()
{
	return (m_uButton & MK_MBUTTON) != 0;
}

bool MouseEvent::isDbClick()
{
	return m_isDBClick;
}

bool MouseEvent::isLDbClick()
{
	return isDbClick() && isLButtonDown();
}

bool MouseEvent::isRDbClick()
{
	return isDbClick() && isRButtonDown();
}